//
//  AppTools.m
//  UI - 豆瓣
//
//  Created by dllo on 15/10/28.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AppTools.h"
#import "AFNetworking.h"




@implementation AppTools

+(void)getWithName:(NSString *)name Block:(AppToolsBlock)block{

    NSString *urlEncode = [name stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET:urlEncode parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        block(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        
        
    }];
    
    
    
    
}
+(void)getWithName: (NSString *)name
             block: (EcodeBlock)block{

    NSString *strEcode = [name stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSURL *url = [NSURL URLWithString:strEcode];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];;
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        
        [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        NSData *data1 = data;
        
        block(data1);
    }];
    [task resume];
    
    
}
@end
